home *** CD-ROM | disk | FTP | other *** search
- // Wall.cs -- A class representing an impassable wall in the game.
- using System;
- using System.Drawing;
-
- namespace GameClasses {
- public class Wall {
- public const int HORIZONTAL = 1;
- public const int VERTICAL = 2;
- public const int DEF_THICKNESS = 8;
-
- public int orientation;
- public Point start;
- public int length;
- public int thickness;
-
- private Brush brush;
- private Color color;
- private Rectangle rect;
-
- public Wall(int orientation, Point start, int length, Color color) :
- this(orientation, start, length, DEF_THICKNESS, color) {}
-
- public Wall(int orientation, Point start, int length,
- int thickness, Color color) {
- this.orientation = orientation;
- this.start = start;
- this.length = length;
- this.thickness = thickness;
- this.color = color;
-
-
- rect = new Rectangle(start, (orientation == HORIZONTAL) ?
- new Size(length, thickness) : new Size(thickness, length));
- this.brush = new SolidBrush(this.color);
- }
-
- public bool Intersects(AnimatedImage obj) {
- int x = obj.imagePosX, y = obj.imagePosY;
- int x2 = obj.imagePosX + obj.imageWidth;
- int y2 = obj.imagePosY + obj.imageHeight;
- int _x = rect.X, _y = rect.Y;
- int _x2 = rect.X + rect.Width, _y2 = rect.Y + rect.Height;
-
- return ((x >= _x && x <= _x2) || (x2 >= _x && x2 <= _x2) ||
- (_x >= x && _x <= x2) || (_x2 >= x && _x2 <= x2)) &&
- ((y >= _y && y <= _y2) || (y2 >= _y && y2 <= _y2) ||
- (_y >= y && _y <= y2) || (_y2 >= y && _y2 <= y2));
- }
-
- public void Display(Graphics g) {
- g.FillRectangle(brush, rect);
- }
-
- public Rectangle getRectangle() {
- return(rect);
- }
- }
- }
-